<template>
    <div>
        <el-container>
            <el-aside width="160px" class="menu-container flex align-center flex-column">
                <div :class="['menu-item flex align-center flex-column',{ 'active': menuIndex == index }]" v-for="(item, index) in menus" :key="index" @click="changeComponent(index, item.componentName)">
                    <el-icon size="50"><House /></el-icon>
                    <div>{{ item.name }}</div>
                </div>
            </el-aside>
            <el-main>
              <keep-alive>
                <component :is="componentName"></component>
              </keep-alive>
            </el-main>
        </el-container>
    </div>
</template>

<script setup>
import { ref, markRaw, onMounted, reactive } from 'vue'
import { House } from "@element-plus/icons-vue";
import IntellectScript from './components/IntellectScript.vue'
import IntellectScenery from './components/IntellectScenery.vue'
import IntellectInteract from './components/IntellectInteract.vue'
import IntellectMood from './components/IntellectMood.vue'

const components = reactive({
    "IntellectScript": markRaw(IntellectScript),
    "IntellectScenery": markRaw(IntellectScenery),
    "IntellectInteract": markRaw(IntellectInteract),
    "IntellectMood": markRaw(IntellectMood)
})
const componentName = ref("")

const menuIndex = ref(0)
const menus = ref([
  {
    name: '智能话术',
    icon: 'el-icon-setting',
    componentName: 'IntellectScript',
  },
  {
    name: '智能布景',
    icon: 'el-icon-setting',
    componentName: 'IntellectScenery',
  },
  {
    name: '智能互动',
    icon: 'el-icon-setting',
    componentName: 'IntellectInteract',
  },
  {
    name: '智能氛围',
    icon: 'el-icon-setting',
    componentName: 'IntellectMood',
  }
])

const changeComponent = (i, name) => {
  console.log(componentName)
  menuIndex.value = i
  componentName.value = components[name]
}

onMounted(() => {
    componentName.value = components["IntellectScript"]
})
</script>

<style lang="less" scoped>
:deep(.el-container){
  height: calc(100vh - 90px);
}
.menu-container {
  width: 150px;
  height: 100%;
  background-color: @bg-default;
  margin-right:20px;
  padding:20px 0;
  box-sizing: border-box;
  overflow: hidden;
  align-items: center;


  .menu-item{
    cursor: pointer;
    color: @font-color-default;
    margin-bottom: 40px;

    &.active{
      color: @color-white
    }
  }
}
</style>
